﻿using Localization.Resources.AbpUi;
using EcoSystem.Localization;
using Volo.Abp.AspNetCore.Mvc;
using Volo.Abp.Localization;
using Volo.Abp.Modularity;
using Microsoft.Extensions.DependencyInjection;
using Microsoft.AspNetCore.Http;

namespace EcoSystem;

[DependsOn(
    typeof(EcoSystemApplicationContractsModule),
    typeof(AbpAspNetCoreMvcModule))]
public class EcoSystemHttpApiModule : AbpModule
{
    public override void PreConfigureServices(ServiceConfigurationContext context)
    {
        PreConfigure<IMvcBuilder>(mvcBuilder =>
        {
            mvcBuilder.AddMvcOptions(options =>
            {
                options.ModelBinderProviders.Insert(0, new DictionaryRequestBinderProvider());
            });
            mvcBuilder.AddApplicationPartIfNotExists(typeof(EcoSystemHttpApiModule).Assembly);
        });
    }

    public override void ConfigureServices(ServiceConfigurationContext context)
    {
        context.Services.AddHttpClient();
        context.Services.AddSingleton<IHttpContextAccessor, HttpContextAccessor>();
        
        Configure<AbpLocalizationOptions>(options =>
        {
            options.Resources
                .Get<EcoSystemResource>()
                .AddBaseTypes(typeof(AbpUiResource));
        });
    }
}
